<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.time.format.DateTimeFormatter" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生考试管理系统 - 成绩查询</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
<!-- 导航栏 -->
<nav class="navbar navbar-expand-lg navbar-light bg-light">
    <div class="container">
        <a class="navbar-brand" href="${pageContext.request.contextPath}/dashboard">
            <i class="fa fa-graduation-cap mr-2"></i>学生考试管理系统
        </a>

        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link" href="${pageContext.request.contextPath}/dashboard">仪表盘</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="${pageContext.request.contextPath}/exams">在线考试</a>
                </li>
                <li class="nav-item active">
                    <a class="nav-link" href="${pageContext.request.contextPath}/scores">成绩查询</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="${pageContext.request.contextPath}/profile">个人信息</a>
                </li>
            </ul>

            <ul class="navbar-nav ms-auto">
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                        <i class="fa fa-user-circle mr-1"></i>${sessionScope.student.name} (${sessionScope.student.studentId})
                    </a>
                    <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
                        <li><a class="dropdown-item" href="${pageContext.request.contextPath}/profile">个人信息</a></li>
                        <li><a class="dropdown-item" href="${pageContext.request.contextPath}/changePassword">修改密码</a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item" href="${pageContext.request.contextPath}/logout">退出登录</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</nav>

<!-- 主内容 -->
<div class="container mt-4">
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <div>
                        <i class="fa fa-list-alt mr-2"></i>我的成绩单
                    </div>
                    <form class="d-flex" action="${pageContext.request.contextPath}/scores" method="GET">
                        <input class="form-control me-2" type="search" placeholder="输入课程名称关键字" name="keyword" aria-label="Search" value="${param.keyword}">
                        <button class="btn btn-outline-primary" type="submit">搜索</button>
                    </form>
                </div>
                <div class="card-body">
                    <c:choose>
                        <c:when test="${not empty scores}">
                            <table class="table table-hover">
                                <thead>
                                <tr>
                                    <th>考试名称</th>
                                    <th>提交时间</th>
                                    <th>得分</th>
                                    <th>状态</th>
                                </tr>
                                </thead>
                                <tbody>
                                <c:forEach var="score" items="${scores}">
                                    <tr>
                                        <td>${score.exam.examName}</td>
                                        <td>${score.examTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))}</td>
                                        <td>
                                            <c:choose>
                                                <c:when test="${score.score >= 60}">
                                                    <span class="badge bg-success">${score.score}</span>
                                                </c:when>
                                                <c:otherwise>
                                                    <span class="badge bg-danger">${score.score}</span>
                                                </c:otherwise>
                                            </c:choose>
                                        </td>
                                        <td>
                                           <c:choose>
                                                <c:when test="${score.score >= 60}">
                                                    <span class="text-success">及格</span>
                                                </c:when>
                                                <c:otherwise>
                                                    <span class="text-danger">不及格</span>
                                                </c:otherwise>
                                            </c:choose>
                                        </td>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                        </c:when>
                        <c:otherwise>
                            <div class="text-center py-4">
                                <i class="fa fa-info-circle fa-3x text-muted mb-3"></i>
                                <p class="text-muted">暂无成绩信息</p>
                            </div>
                        </c:otherwise>
                    </c:choose>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 页脚 -->
<footer class="bg-light text-center text-muted mt-5 py-3">
    <div class="container">
        <p>© 2025 学生考试管理系统 | 由管理员分配账户</p>
    </div>
</footer>
</body>
</html>